# -*- coding: utf-8 -*-
import configparser
import os


class Config():
    def __init__(self):
        parser = configparser.ConfigParser()
        base_path = os.path.split(os.path.realpath(__file__))[0]
        with open(os.path.join(base_path, 'config.ini'), encoding='utf-8') as f:
            parser.read_file(f)

            self.email = parser.get('global', 'email')
            self.password = parser.get('global', 'password')
            self.fault_to = self.format_many_values_config(parser.get('global', 'fault_to'))
            """:type : list[str]"""
            self.ip_changed_to = self.format_many_values_config(parser.get('global', 'ip_changed_to'))
            """:type : list[str]"""

            self.interval = int(parser.get('global', 'interval'))

            self.smtp = EmailConfig(parser.get('smtp', 'address'), parser.get('smtp', 'port'), parser.get('smtp', 'use_ssl'))
            self.pop = EmailConfig(parser.get('pop', 'address'), parser.get('pop', 'port'), parser.get('pop', 'use_ssl'))

    @staticmethod
    def format_many_values_config(value):
        if value:
            return value.split(';')
        return []


class EmailConfig():
    def __init__(self, address, port, use_ssl):
        self.address = address
        self.port = port
        self.use_ssl = bool(use_ssl)


config = Config()